package com.xqboss.common.enums;

import com.baomidou.mybatisplus.annotation.IEnum;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonValue;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;

import java.io.Serializable;
import java.util.Arrays;
import java.util.Optional;

/**
 * @author Trent
 * @date 2023/8/18
 */
@JsonDeserialize(using = EnumJsonDeserializer.class)
public interface BaseEnum<T extends Serializable> extends IEnum<T> {

    @Override
    @JsonValue
    T getValue();

    public String getMsg();

    static <E extends Enum<?> & BaseEnum<Serializable>> Optional<E> valueOf(Class<E> enumClass, Serializable code) {
        return Arrays.stream(enumClass.getEnumConstants()).filter(e -> e.getValue() == code).findAny();
    }

}
